<?php

class App_Model_DbTable_Avatar extends Ext_Db_Table  
{  
    protected $_name = 'avatar';
    
    private static $_avatar = array();
    
    public function getRowById($id)
    {
        if(!$id)
        {
            return "";
        }
        
        if(isset(self::$_avatar['id'][$id]))
        {
            return self::$_avatar['id'][$id];
        }
        
        $db = $this->getAdapter();
        $safe = $db->quoteInto(" id = ? ", $id);
        $row = $this->fetchRow($safe);
        if (!$row) {
            return "";
        }
        $avatar = $row->toArray();

        self::$_avatar['id'][$id] = $avatar;

        return $avatar;
    }

    public function addNew($inputArray)
    {
        $sql_data_array = array();
        if(array_key_exists('big', $inputArray)) $sql_data_array['big'] = $inputArray['big'];
        if(array_key_exists('middle', $inputArray)) $sql_data_array['middle'] = $inputArray['middle'];
        if(array_key_exists('small', $inputArray)) $sql_data_array['small'] = $inputArray['small'];
        if(array_key_exists('thumb', $inputArray)) $sql_data_array['thumb'] = $inputArray['thumb'];

        try {
            $rows_affected = $this->insert($sql_data_array);
            $last_insert_id = $this->getAdapter()->lastInsertId();
        }catch (Exception $e){
            trigger_error($e->getMessage(), E_USER_WARNING);
        }
        return $last_insert_id;
    }
}  

